package com.gpStudy.design.single;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class BreakSingletonSeriableTest {
    public static void main(String[] args) {

        LazySingleton o1 = null;
        LazySingleton o2 = LazySingleton.getInstance();

        FileOutputStream fos = null;
        try {

            fos = new FileOutputStream("LazySingleton.obj");

            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(o2);
            oos.flush();
            oos.close();

            FileInputStream fis = new FileInputStream("LazySingleton.obj");
            ObjectInputStream ois = new ObjectInputStream(fis);
            o1 = (LazySingleton)ois.readObject();

            System.out.println(o1 == o2);

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
